<?php
defined('SEJUJOPEFDNGJSL') or exit('Access denied');

$pagecount=getnums($_GET["pagecount"],$GLOBALARR['pagecount']);
$option=checkstr($_GET['option']);
$orderby=checkstr(getnums($_GET['orderby'],1));
$quser=checkstr(trim($_GET['quser']));

$tmp_arr['toption'].='<a class="thabtn" href="'.getqueurl('option',0).'">全部</a><a class="thabtn" href="'.getqueurl('option',1).'">利息</a><a class="thabtn" href="'.getqueurl('option',2).'">冻结团队收益</a><a class="thabtn" href="'.getqueurl('option',4).'">已释放团队收益</a>
	';
	// //<a class="thabtn" href="'.getqueurl('option',5).'">冻结晋级奖</a>
	// <a class="thabtn" href="'.getqueurl('option',6).'">已释放晋级奖</a>
	// <a class="thabtn" href="'.getqueurl('option',7).'">冻结渠道奖</a>
	// <a class="thabtn" href="'.getqueurl('option',8).'">已释放渠道奖</a>

$tmp_arr['torderby']='<a href="'.getqueurl('orderby',geteqval(array($orderby,1,'2','1'))).'" class="'.((strstr($orderby,'1')||strstr($orderby,'2'))?"tpaixusel":"tpaixu").'">'.geteqval(array($orderby,1,'时间↑','时间↓')).'</a>';

if(is_array($GLOBALARR['jjname'])){
foreach ($GLOBALARR['jjname'] as $k => $v) {
	$tmp_arr['tcolor'].='<a href="javascript:;" class="theacolor levelcolor'.$k.'">'.$v.'</a>';
}
}

$condition=' where 1=1 ';

if($quser){
		$query_user = $member->getuv($quser);
		if(!$query_user){
			msg_b("无此用户");
		}
		$condition.=" and uid = ".$query_user['id'];
	
}
if($option==1){
	$condition.=" and prize_option = 51";
}elseif($option==2){
	$condition.=" and prize_option = 54 and prize_status=0";
}elseif($option==3){
	$condition.=" and prize_option = 54";
}elseif($option==4){
	$condition.=" and prize_option = 54 and prize_status=1";
}elseif($option==5){
	$condition.=" and prize_option = 62 and prize_status=0";
}elseif($option==6){
	$condition.=" and prize_option = 62 and prize_status=1";
}elseif($option==7){
	$condition.=" and prize_option = 55 and prize_status=0";
}elseif($option==8){
	$condition.=" and prize_option = 55 and prize_status=1";
}

$order='';
if($orderby==1) $order=' order by prize_ltime asc';
if($orderby==2) $order=' order by prize_ltime desc';


$tmp_arr['tth']='<th>序号</th><th>会员账号</th>';
$tmp_arr['tth'].='<th>时间</th><th>发放时间</th><th>类型</th><th>金额</th><th>备注</th>';
$psql="select count(0) from ld_prize_list $condition";
$db->query($psql,3);
$pcount=$db->fval;
$pagecount=$pagecount;   //每页条数 
$astr="&lsaction=prizedetail&pagecount=$pagecount&orderby=$orderby&option=$option&quser=$quser";	  //Url
$pagearr=pagelist($pagecount,$pcount,$astr);
$offset=$pagearr[1];

$sql="select * from ld_prize_list  $condition $order limit $offset,$pagecount";
$db->query($sql);
$ii=0;
foreach ($db->rs as $k => $v) {
	$ii++;
	$serialid=($pagearr[2]-1)*$pagecount+$ii;
	if($v['prize_option'] == 51){
		$prize_type = '利息';
	}elseif($v['prize_option'] == 52){
		$prize_type = '团队收益';
	}elseif($v['prize_option'] == 54){
		$prize_type = '团队收益';
	}elseif($v['prize_option'] == 55){
		$prize_type = '渠道奖';
	}elseif($v['prize_option'] == 62){
		$prize_type = '晋级奖';
	}

	if(empty($v['grant_time'])){
        $grant_time = "--";
    }else{
        $grant_time = date("Y-m-d H:i:s",$v['grant_time']);
    }
	$rm=$member->getuvinfo($v['uid']);
	$tmp_arr['ttr'].='<tr class="levelcolor'.$rm['user_level'].'">
						<td><span  title="'.$rm["id"].'">'.$serialid.'</span></td>
						<td>'.$rm['uname'].'</td>
						';						
	$tmp_arr['ttr'].='<td>'.date("Y-m-d H:i:s",$v['prize_ltime']).'</td>
							<td>'.$grant_time.'</td>
							<td>'.$prize_type.'</td>
							<td>'.$v['amount'].'</td>
							<td>'.$v['description'].'</td></tr>';
}


$tmp_arr['tcount']=$pcount;
$tmp_arr['ttitle']=getmenu($GLOBALARR['menu'],'prizedetail');
$tmp_arr['tpage']=$pagearr[0];

admin_two($tmp_arr);
$uuid=" and 1=1 ";
if($quser){
		$uuid.=" and  uid = ".$query_user['id'];
}
if(empty($_GET['option'])){
	$db->query("select SUM(amount) as am from ld_prize_list",2);
	$heji = $db->rs;
	echo "<div style='font-size:14px;'><span>全部奖金合计：".$heji['am']."</span></div>";
}
if($_GET['option'] == 1){
	$db->query("select SUM(amount) as am from ld_prize_list where prize_option = 51",2);
	$heji = $db->rs;
	echo "<div style='font-size:14px;'><span>利息合计：".$heji['am']."</span></div>";
}
if($_GET['option'] == 2){
	$db->query("select SUM(amount) as am from ld_prize_list where prize_option = 52 and prize_status=0 $uuid",2);
	$heji = $db->rs;
	echo "<div style='font-size:14px;'><span>推广提成合计：".$heji['am']."</span></div>";
}
if($_GET['option'] == 4){
	$db->query("select SUM(amount) as am from ld_prize_list where prize_option = 52 and prize_status=1 $uuid",2);
	$heji = $db->rs;
	echo "<div style='font-size:14px;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>推广提成合计：".$heji['am']."</span></div>";
    //1代
	$db->query("select SUM(amount) as am from ld_prize_list where prize_option = 52 and lx_generation=1 and prize_status=1 $uuid",2);
	$heji = $db->rs;
	echo "<div style='font-size:14px;'><span>1代推广提成合计：".$heji['am']."</span></div>";
    //2代
	$db->query("select SUM(amount) as am from ld_prize_list where prize_option = 52 and lx_generation=2  and prize_status=1 $uuid",2);
	$heji = $db->rs;
	echo "<div style='font-size:14px;'><span>2代推广提成合计：".$heji['am']."</span></div>";
    //4代
	$db->query("select SUM(amount) as am from ld_prize_list where prize_option = 52 and lx_generation=4 and prize_status=1 $uuid",2);
	$heji = $db->rs;
	echo "<div style='font-size:14px;'><span>4代推广提成合计：".$heji['am']."</span></div>";
}
if($_GET['option'] == 5){
	$db->query("select SUM(amount) as am from ld_prize_list where prize_option = 62 and prize_status=0 $uuid",2);
	$heji = $db->rs;
	echo "<div style='font-size:14px;'><span>推广提成合计：".$heji['am']."</span></div>";
}
if($_GET['option'] == 6){
	$db->query("select SUM(amount) as am from ld_prize_list where prize_option = 62 and prize_status=1 $uuid",2);
	$heji = $db->rs;
	echo "<div style='font-size:14px;'><span>推广提成合计：".$heji['am']."</span></div>";
}
?>